<template>
	<view>
		<view class="uni-container" style="float: left;">
            <span>看视频奖励倍数设置</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="最少" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="videofanbei.min" style="width: 200px;"/>
				</uni-forms-item>
                <uni-forms-item label="最多" name="title" labelWidth="150">
                	<input class="uni-input-border" type="number" v-model="videofanbei.max" style="width: 200px;"/>
                </uni-forms-item>
				
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"videofanbei":{
					"min": 0,
					"max": 0,
				},    
					
			}
		},
		methods: {
			getinfo(){
				var self = this
				this.isLoading = true
				self.data = []
				this.$request('admin/loadconfig',{id:'videofanbei'}).then(res => {
					this.isLoading = false
					var json = res.config
					self.videofanbei = json
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			},
			save(){
				var self = this
                if(Number(self.videofanbei['max'])<Number(self.videofanbei['min'])){
                    uni.showToast({
                    	title: "最大值必须大于最小值",
                    	icon: 'none',
                    	duration: 2000
                    })
                    return
                }
				self.isLoading = true
				delete self.videofanbei._id;
				for(let key in self.videofanbei){
					if(key != '_id'){
						self.videofanbei[key] = Number(self.videofanbei[key])
					}
				}
				console.log(self.videofanbei)
				self.$request('admin/setconfig',{json:JSON.stringify({videofanbei:self.videofanbei})}).then(res => {
					self.isLoading = false
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			}
		},
		mounted() {
			var self = this
			self.getinfo()
		}
	}
</script>

<style>

</style>
